import uuid

from sqlalchemy import Column, text
from sqlalchemy.dialects.postgresql import UUID

from sqlalchemy.orm import declarative_mixin


@declarative_mixin
class UUIDMixin:
    """Mixin for rewrite integer id field to uuid4 id field."""
    id = Column(
        UUID(as_uuid=True),
        default=uuid.uuid4,
        server_default=text("gen_random_uuid()"),
        primary_key=True,
    )
